<?php
/**
* @version      1.1.0
* @package	ResMania Search
* @copyright	Copyright (C) 2009 - 2010. All rights reserved.
* @license	GNU/GPL
* This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License.
* see http://resmania.com/license for more information.
*/

// no direct access
defined('_JEXEC') or die('Restricted access');

/**
* ResMania Search Form
*/
class modResManiaSearch
{
    /**
    * get the Search Module Configuration
    *
    * This collects the configuration for the search form and returns it.
    *
    * @return 	object	the search configuration
    */
    function getConfig(){

       $this->siteroot = JURI::root();

       $connectorPath = JPATH_SITE . DS . 'administrator' . DS . 'components'. DS . 'com_resmania' . DS . 'classes' . DS . 'RM' . DS . 'Joomla' . DS . 'Connector.php';
       $coreConnector = JPATH_SITE . DS . 'RM' . DS . 'system' . DS . 'application' . DS . 'classes' . DS . 'RM' . DS . 'Connector.php';

        if (file_exists($connectorPath) && file_exists($coreConnector)){

            require_once $connectorPath;
            
            RM_Connector::setup('RM_Joomla_Connector', 'user');
            $connector = RM_Connector::getInstance();
            $connector->initialize();

            $this->postto = RM_Environment::getInstance()->getRouter()->_('Unit', 'list');

            $config = new RM_Config();
            $dateFormat = $config->getJSDateformat();

            if ($dateFormat == "d/m/Y"){
                $jsDateFormat = "%d/%m/%Y";
                $lng_dateFormat = "dd/mm/yyyy";
                $phpDateFormat = "d/m/Y";
            } else {
                $jsDateFormat = "%m/%d/%Y";
                $lng_dateFormat = "mm/dd/yyyy";
                $phpDateFormat = "m/d/Y";
            }

            $criteria = RM_Reservation_Manager::getInstance()->getCriteria(); // get any saved dates
            if ($criteria !== null){
                $this->start_datetime = $criteria->start_datetime ? date($phpDateFormat, strtotime($criteria->start_datetime)) : $lng_dateFormat;
                $this->end_datetime = $criteria->end_datetime ? date($phpDateFormat, strtotime($criteria->end_datetime)) : $lng_dateFormat;
            } else {
                $this->start_datetime = $lng_dateFormat;
                $this->end_datetime = $lng_dateFormat;
            }

            $this->dp_dateformat = $jsDateFormat;
            $this->dp_lng_dateformat = $lng_dateFormat;
        } else {
            $this->dp_dateformat = "%d/%m/%Y";
            $this->dp_lng_dateformat = "dd/mm/yyyy";
        }

        return $this;
    }

}
